package com.jenkin.jcache;

import com.jenkin.jcache.realize.CacheFactory;
import com.jenkin.jcache.realize.MapCache;

/**
 * 哈希表缓存测试类
 * @author yangjie
 *
 */
public class MyMapCache{

	private static MapCache<String, String> newsCache = CacheFactory.getMapCache("newsCache", 5);
	
	static {
		initializeData();
		newsCache.addFillListener(() ->{
			fillData();
		});
	}
	
	/**
	 * 第一次初始化数据
	 */
	public static void initializeData() {
		for(int i=0; i<100; i++) {
			newsCache.add("a"+i, "good");
		}
	}
	
	/**
	 * 过期后改变数据
	 */
	public static void fillData() {
		for(int i=0; i<100; i++) {
			newsCache.add("a"+i, "nice");
		}
	}
	
	public static String get(String key) {
		return newsCache.get(key);
	}
	
	public static boolean containsKey(String key) {
		return newsCache.containsKey(key);
	}

}
